﻿using System;
using System.Linq;
using System.Windows.Data;

namespace SoftSource.Timecard.Converters
{
    public sealed class ProjectIDToCategoriesConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value != null && value is int)
            {
                int id = (int)value;

                var projectCategories = App.Model.ProjectCategories.Entities.Where(pc => pc.ProjectID == id);
                var categories = App.Model.Categories.Entities.Where(c => projectCategories.Any(pc => pc.CategoryID == c.CategoryID));
                return categories;
            }
            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
